﻿using System;
using System.Collections.Generic;
using System.Text;
using KBEngine.Setting.TypeDef;

namespace KBEngine.Export
{
    public abstract class PythonExport
    {
        protected virtual string GetTypeName(IType iType, bool switchBaseName = true)
        {
            var type = iType.GetType();
            if (type == typeof(BaseType))
                return switchBaseName ? GetPythonBaseName(iType.TypeName) : iType.TypeName;
            else if (type == typeof(AliasType))
                return GetTypeName(((AliasType)iType).RealType, switchBaseName);
            else if (type == typeof(ArrayType))
                return $"List[{GetTypeName(((ArrayType)iType).ElementType, switchBaseName)}]";
            else if (type == typeof(UserType))
                return iType.TypeName;

            throw new InvalidOperationException("GetTypeName() " + type.Name);
        }
        private string GetPythonBaseName(string baseName)
        {
            switch (baseName)
            {
                case "UINT8":
                case "UINT16":
                case "UINT32":
                case "UINT64":
                    return "int";

                case "INT8":
                case "INT16":
                case "INT32":
                case "INT64":
                    return "int";

                case "FLOAT":
                case "DOUBLE":
                    return "int";

                case "VECTOR2":
                    return "Vector2";
                case "VECTOR3":
                    return "Vector3";
                case "VECTOR4":
                    return "Vector4";

                case "STRING":
                    return "str";
                case "UNICODE":
                    return "str";
                case "PYTHON":
                    return "any";
                case "PY_DICT":
                    return "Dict";
                case "PY_TUPLE":
                    return "Tuple";
                case "PY_LIST":
                    return "List";
                case "MAILBOX":
                    return "any";
                case "BLOB":
                    return "any";
                case "ENTITYCALL":
                    return "any";
                default:
                    throw new InvalidOperationException("GetPythonBaseName() " + baseName);
            }
        }
    }
}
